package fr.gestproj.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.eclipse.persistence.annotations.Index;

/**
 *
 * @author Anne
 */
@Entity
@Table(name = "profil")
public class Profil implements Serializable {

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Index
    @Size(max = 100)
    @NotNull
    @Column(name = "libelle", length = 100, nullable = false)
    private String libelle;

    @NotNull
    @Column(name = "controle_total", nullable = false)
    private boolean controleTotal;

    @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
    @JoinTable(name = "profil_role", joinColumns = {
        @JoinColumn(name = "ref_profil", referencedColumnName = "id")}, inverseJoinColumns = {
        @JoinColumn(name = "ref_role", referencedColumnName = "code")})
    private List<Role> listeRole;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getLibelle() {
        return libelle;
    }

    public void setLibelle(String libelle) {
        this.libelle = libelle;
    }

    public boolean isControleTotal() {
        return controleTotal;
    }

    public void setControleTotal(boolean controleTotal) {
        this.controleTotal = controleTotal;
    }

    public List<Role> getListeRole() {
        if (listeRole == null) {
            listeRole = new ArrayList();
        }
        return listeRole;
    }

    public void setListeRole(List<Role> listeRole) {
        this.listeRole = listeRole;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Profil)) {
            return false;
        }
        Profil other = (Profil) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "fr.gestproj.model.Profil[ id=" + id + " ]";
    }

}
